<?php

class Odbtp extends CI_Controller {
	

	function __construct()
	{
		parent::__construct();
		
		$this->load->model('Test_Query_model');
		$this->load->model('Test_Query_Helper_model');
		$this->load->model('Test_Active_Record_model');
		//$this->load->model('Test_Transactions_model');
		//$this->load->model('Test_Metadata_model');
		
	}
	
	function index()
	{		
		//phpinfo();
	}
	
	function test()
	{		
		//load query example from odbtp example files
		//$this->load->view('query.php');		
		
		//////////////////  Testing the Query Object ////////////////////
		
		//var_dump($this->Test_Query_model->test_query());
		
		//echo "<br />\n";
		
		echo "<h1>ODBTP Test Results</h1>";
		
		echo "<h2>Testing Query Object</h2>";
		
		echo "<strong>Test result_object: </strong>";
		var_dump($this->Test_Query_model->test_result_object());
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		echo "<strong>Test result_array: </strong>";
		var_dump($this->Test_Query_model->test_result_array());
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		echo "<strong>num_rows: </strong>". $this->Test_Query_model->test_num_rows();
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		echo "<strong>num_fields: </strong>". $this->Test_Query_model->test_num_fields();
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		echo "<strong>Test row: </strong>";
		var_dump($this->Test_Query_model->test_row());
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		// @todo nth row not returning yet
		//var_dump($this->Test_Query_model->test_row(3));
		
		//////////////////  Testing the Query Helper Functions  ///////////////////
		
		echo "<h2>Testing Query Helper Functions</h2>";
		
		echo "<strong>Version: </strong>" . $this->Test_Query_Helper_model->test_version();
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		echo "<strong>Platform: </strong>" . $this->Test_Query_Helper_model->test_platform();
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		echo "<strong>Count All: </strong>" . $this->Test_Query_Helper_model->test_count_all();
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		//echo "Last query: " . $this->Test_Query_Helper_model->test_last_query();
		
		//echo "<hr />\n";
		
		//////////////////   Testing the Active Record Class  ///////////////////////
		
		echo "<h2>Testing Active Record Class</h2>";
		
		echo "<strong>Test get: </strong>";
		var_dump($this->Test_Active_Record_model->test_get());	
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		echo "<strong>Test get_limit: </strong>";
		var_dump($this->Test_Active_Record_model->test_get_limit());
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		echo "<strong>Test get_where: </strong>";
		var_dump($this->Test_Active_Record_model->test_get_where());	
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		echo "<strong>Test select: </strong>";
		var_dump($this->Test_Active_Record_model->test_select());
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		echo "<strong>Test select_max: </strong>";
		var_dump($this->Test_Active_Record_model->test_select_max());
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		echo "<strong>Test select_min: </strong>";
		var_dump($this->Test_Active_Record_model->test_select_min());
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		echo "<strong>Test select_avg: </strong>";
		var_dump($this->Test_Active_Record_model->test_select_avg());
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		echo "<strong>Test select_sum: </strong>";
		var_dump($this->Test_Active_Record_model->test_select_sum());	
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";

		echo "<strong>Test insert: </strong>";
		var_dump($this->Test_Active_Record_model->test_insert());
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		echo "<strong>Test update: </strong>";
		var_dump($this->Test_Active_Record_model->test_update());
		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";	
	
		echo "<strong>Test delete: </strong>";
		var_dump($this->Test_Active_Record_model->test_delete());
		
		echo "<h3>Affected Rows: " . $this->Test_Query_Helper_model->test_affected_rows() . "</h3>\n";		
		echo "<h3>Last query: " . $this->Test_Query_Helper_model->test_last_query() . "</h3><hr />\n";
		
		echo "<h2>Testing Active Record Class</h2>";
		
		echo "<strong>Test list_tables: </strong>";
		//var_dump($this->Test_Metadata_model->test_list_tables());
		//// not working in MSAccess, need platform specific code "SELECT [Name] FROM MSysObjects WHERE [Type] = 6"
		
		echo "<hr />\n";
		
		echo "<strong>Test table_exists: </strong>";
		//var_dump($this->Test_Metadata_model->test_table_exists());
		
		echo "<hr />\n";
		
		echo "<strong>Test list_fields: </strong>";
		//var_dump($this->Test_Metadata_model->test_list_fields());
		// not working in MSAccess, need platform specific code "SELECT * FROM MSysObjects WHERE [Type] = 1 AND Left([Name],4) <> 'MSys'"
		
		echo "<hr />\n";
		
		echo "<strong>Test field_exists: </strong>";
		//var_dump($this->Test_Metadata_model->test_field_exists());
		
		echo "<hr />\n";
		
		echo "<strong>Test field_data: </strong>";
		//var_dump($this->Test_Metadata_model->test_field_data());
		
		echo "<hr />\n";
		
		
	}
}